{
    _CP_.OPTIONS_HANDLER.set('readonly', {
        [U.F.argType.any]: (value: any) => { return Boolean(value); },
    });
}

type Toptions_READONLY = {
    /** 只读状态 */
    readonly?: boolean;
};

interface KHTMLElement {
    /**
     * 设置只读状态
     * @returns 当前元素对象
     */
    readonly(): KHTMLElement;
}
{
    Object.defineProperty(KHTMLElement.prototype, 'readonly', {
        writable: false,
        configurable: false,
        enumerable: false,
        value: function (this: KHTMLElement) {
            const plugin = this.getPlugin();
            if (plugin) {
                const creator = plugin.ele()!.creator;
                if ('readonly' in creator!) {
                    (creator as any).readonly();
                }
                plugin.addClass(_CP_.CLASSES.READONLY);
            }
            return this;
        }
    });
}
interface KHTMLElement {
    /**
     * 设置可写状态
     * @returns 当前元素对象
     */
    editable(): KHTMLElement;
}
{
    Object.defineProperty(KHTMLElement.prototype, 'editable', {
        writable: false,
        configurable: false,
        enumerable: false,
        value: function (this: KHTMLElement) {
            const plugin = this.getPlugin();
            if (plugin) {
                const creator = plugin.ele()!.creator;
                if ('editable' in creator!) {
                    (creator as any).editable();
                }
                plugin.removeClass(_CP_.CLASSES.READONLY);
            }
            return this;
        }
    });
}

/**
 * 只读控件注解
 * @param target 目标类型
 */
function ACreadonly(target: any) {
    if (!U.isSubClass(__CVP__, target)) { return; }

    // 处理器
    const original_options_handlers = target.prototype.options_handlers;
    target.prototype.options_handlers = function (this: __CVP__<any>) {
        const options_handlers = original_options_handlers.call(this);

        U.O.setDefaultValue(options_handlers, 'readonly', _CP_.OPTIONS_HANDLER.get('readonly'));

        return options_handlers;
    };

    // 初始化
    const original_afterInitializer = target.prototype.afterInitializer;
    target.prototype.afterInitializer = function (this: __CVP__<any>) {
        original_afterInitializer.call(this);

        // 只读状态
        if (this.options.readonly) {
            this.ele.readonly();
        }
    };
}
